package com.yoga.utils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTCreator;
import com.auth0.jwt.algorithms.Algorithm;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Map;

/**
 * @author yan
 * @date 2025/8/19
 */
public class JwtUtil {
    public static String createJwt(String id, String username, Map<String, Object> payloads, LocalDateTime expires, String secret) {
        JWTCreator.Builder builder = JWT.create();
        String jwt = builder.withPayload(payloads).withExpiresAt(expires.toInstant(ZoneOffset.of("+8")))
                .withIssuer("yoga")
                .withIssuedAt(Instant.now())
                .withSubject("身份认证")
                .withAudience(username)
                .withJWTId(id)
                .sign(Algorithm.HMAC256(secret));

        return jwt;
    }

}
